/*
 * ============================================================================
 *
 *       Filename:  IPRecordThreadReader.h
 *
 *    Description:  header file
 *
 *         Author:  liangqing
 *
 * ============================================================================
 */
#ifndef IPRECORDTHREADREADER_H
#define IPRECORDTHREADREADER_H

#include "IPRecordReader.h"
#ifdef WIN32
#include <windows.h>
#include <process.h>
#endif /* WIN32 */

class IPRecordThreadReader : public IPRecordReaderQueue {
  public:
#ifdef WIN32
    IPRecordThreadReader(const char *filename, int size);
#else
    IPRecordThreadReader(const char *filename):
                                IPRecordReaderQueue(filename) {}
#endif /* WIN32 */
    
    ~IPRecordThreadReader();

    virtual bool get(IPRecord *record);
  
    virtual void push_reader(IPRecordReaderType type, const char *filename);

  protected:
#ifdef WIN32
    static unsigned __stdcall _run(void *); 

    IPRecord *_pool;
    HANDLE _resource_sem;
    HANDLE _space_sem;
    HANDLE _push_sem;
    CRITICAL_SECTION _critic;
    HANDLE _thread;
    unsigned _thread_id;

    int _size;
    int _read;
    int _write;
    bool _finish;
#endif /* WIN32 */
};

#endif   /* #ifndef IPRECORDTHREADREADER_H */


